package org.petstore.web.servlet;

import org.petstore.domain.Account;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

import static org.petstore.web.servlet.util.ServletUtil.MAIN_FORM;

public class SignOutServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //将用户设置为空，在通过session设置后跳转到主页面
        Account loginUser = null;
        HttpSession session = request.getSession();
        session.setAttribute("loginUser", loginUser);
        request.getRequestDispatcher(MAIN_FORM).forward(request, response);
    }
}
